
#include <doc_panel_base.h>
#include <stdlib.h>
#include <string.h>
#include "utils.h"




enum  {
	DOC_PANEL_BASE_DUMMY_PROPERTY
};
static gboolean doc_panel_base_doc_panel_mutex = FALSE;
static gboolean _doc_panel_base_on_key_press_event_gtk_widget_key_press_event (DocPanelBase* _sender, const GdkEventKey* event, gpointer self);
static void _doc_panel_base_close_gtk_button_clicked (GtkButton* _sender, gpointer self);
static gboolean doc_panel_base_real_on_key_press_event (DocPanelBase* self, DocPanelBase* sender, const GdkEventKey* event);
static gpointer doc_panel_base_parent_class = NULL;
static void doc_panel_base_finalize (GObject* obj);
static int _vala_strcmp0 (const char * str1, const char * str2);


static void g_cclosure_user_marshal_BOOLEAN__VOID (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data);

static gboolean _doc_panel_base_on_key_press_event_gtk_widget_key_press_event (DocPanelBase* _sender, const GdkEventKey* event, gpointer self) {
	return doc_panel_base_on_key_press_event (self, _sender, event);
}


static void _doc_panel_base_close_gtk_button_clicked (GtkButton* _sender, gpointer self) {
	doc_panel_base_close (self);
}


DocPanelBase* doc_panel_base_construct (GType object_type, guint rows, guint columns, gboolean homogeneous, GtkSourceBuffer** source_buff, GtkSourceView** source_view) {
	DocPanelBase * self;
	GtkButton* _tmp1;
	GtkImage* _tmp0;
	g_return_val_if_fail (source_buff != NULL, NULL);
	g_return_val_if_fail (source_view != NULL, NULL);
	self = g_object_newv (object_type, 0, NULL);
	gtk_table_resize ((GtkTable*) self, rows, columns);
	gtk_table_set_homogeneous ((GtkTable*) self, homogeneous);
	self->source_buff = (*source_buff);
	self->source_view = (*source_view);
	g_signal_connect_object ((GtkWidget*) self, "key-press-event", (GCallback) _doc_panel_base_on_key_press_event_gtk_widget_key_press_event, self, 0);
	_tmp1 = NULL;
	_tmp0 = NULL;
	self->close_btn = (_tmp1 = utils_create_small_button (_tmp0 = g_object_ref_sink ((GtkImage*) gtk_image_new_from_stock (GTK_STOCK_CLOSE, GTK_ICON_SIZE_MENU))), (self->close_btn == NULL) ? NULL : (self->close_btn = (g_object_unref (self->close_btn), NULL)), _tmp1);
	(_tmp0 == NULL) ? NULL : (_tmp0 = (g_object_unref (_tmp0), NULL));
	g_signal_connect_object (self->close_btn, "clicked", (GCallback) _doc_panel_base_close_gtk_button_clicked, self, 0);
	gtk_table_attach ((GtkTable*) self, (GtkWidget*) self->close_btn, columns - 1, columns, (guint) 0, (guint) 1, GTK_SHRINK, GTK_SHRINK, (guint) 5, (guint) 0);
	gtk_widget_set_no_show_all ((GtkWidget*) self, TRUE);
	return self;
}


DocPanelBase* doc_panel_base_new (guint rows, guint columns, gboolean homogeneous, GtkSourceBuffer** source_buff, GtkSourceView** source_view) {
	return doc_panel_base_construct (TYPE_DOC_PANEL_BASE, rows, columns, homogeneous, source_buff, source_view);
}


void doc_panel_base_show (DocPanelBase* self) {
	gboolean _tmp0;
	g_return_if_fail (self != NULL);
	if (!(g_signal_emit_by_name (self, "show-panel", &_tmp0), _tmp0)) {
		gtk_widget_set_no_show_all ((GtkWidget*) self, FALSE);
		gtk_widget_show_all ((GtkWidget*) self);
		gtk_widget_show_now ((GtkWidget*) self);
	}
}


void doc_panel_base_close (DocPanelBase* self) {
	gboolean _tmp0;
	g_return_if_fail (self != NULL);
	if (!(g_signal_emit_by_name (self, "close-panel", &_tmp0), _tmp0)) {
		gtk_widget_hide_all ((GtkWidget*) self);
	}
}


static gboolean doc_panel_base_real_on_key_press_event (DocPanelBase* self, DocPanelBase* sender, const GdkEventKey* event) {
	g_return_val_if_fail (self != NULL, FALSE);
	g_return_val_if_fail (sender != NULL, FALSE);
	if (_vala_strcmp0 (gdk_keyval_name ((*event).keyval), "Escape") == 0) {
		doc_panel_base_close (self);
	} else {
		if (_vala_strcmp0 (gdk_keyval_name ((*event).keyval), "Tab") == 0) {
			return TRUE;
		}
	}
	return FALSE;
}


gboolean doc_panel_base_on_key_press_event (DocPanelBase* self, DocPanelBase* sender, const GdkEventKey* event) {
	return DOC_PANEL_BASE_GET_CLASS (self)->on_key_press_event (self, sender, event);
}


static void doc_panel_base_class_init (DocPanelBaseClass * klass) {
	doc_panel_base_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = doc_panel_base_finalize;
	DOC_PANEL_BASE_CLASS (klass)->on_key_press_event = doc_panel_base_real_on_key_press_event;
	g_signal_new ("show_panel", TYPE_DOC_PANEL_BASE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_BOOLEAN__VOID, G_TYPE_BOOLEAN, 0);
	g_signal_new ("close_panel", TYPE_DOC_PANEL_BASE, G_SIGNAL_RUN_LAST, 0, NULL, NULL, g_cclosure_user_marshal_BOOLEAN__VOID, G_TYPE_BOOLEAN, 0);
}


static void doc_panel_base_instance_init (DocPanelBase * self) {
	self->source_buff = NULL;
	self->source_view = NULL;
}


static void doc_panel_base_finalize (GObject* obj) {
	DocPanelBase * self;
	self = DOC_PANEL_BASE (obj);
	(self->close_btn == NULL) ? NULL : (self->close_btn = (g_object_unref (self->close_btn), NULL));
	G_OBJECT_CLASS (doc_panel_base_parent_class)->finalize (obj);
}


GType doc_panel_base_get_type (void) {
	static GType doc_panel_base_type_id = 0;
	if (doc_panel_base_type_id == 0) {
		static const GTypeInfo g_define_type_info = { sizeof (DocPanelBaseClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) doc_panel_base_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DocPanelBase), 0, (GInstanceInitFunc) doc_panel_base_instance_init, NULL };
		doc_panel_base_type_id = g_type_register_static (GTK_TYPE_TABLE, "DocPanelBase", &g_define_type_info, 0);
	}
	return doc_panel_base_type_id;
}


static int _vala_strcmp0 (const char * str1, const char * str2) {
	if (str1 == NULL) {
		return -(str1 != str2);
	}
	if (str2 == NULL) {
		return str1 != str2;
	}
	return strcmp (str1, str2);
}



static void g_cclosure_user_marshal_BOOLEAN__VOID (GClosure * closure, GValue * return_value, guint n_param_values, const GValue * param_values, gpointer invocation_hint, gpointer marshal_data) {
	typedef gboolean (*GMarshalFunc_BOOLEAN__VOID) (gpointer data1, gpointer data2);
	register GMarshalFunc_BOOLEAN__VOID callback;
	register GCClosure * cc;
	register gpointer data1, data2;
	gboolean v_return;
	cc = (GCClosure *) closure;
	g_return_if_fail (return_value != NULL);
	g_return_if_fail (n_param_values == 1);
	if (G_CCLOSURE_SWAP_DATA (closure)) {
		data1 = closure->data;
		data2 = param_values->data[0].v_pointer;
	} else {
		data1 = param_values->data[0].v_pointer;
		data2 = closure->data;
	}
	callback = (GMarshalFunc_BOOLEAN__VOID) (marshal_data ? marshal_data : cc->callback);
	v_return = callback (data1, data2);
	g_value_set_boolean (return_value, v_return);
}



